#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

const int N = 1e5 + 10;

int n, m;

struct Edge
{
    int to, next, dis;
} e[N << 1];

int head[N], idx = 1;
bool st[N];
int dist[N];

void add(int a, int b, int c)
{
    e[idx].to = b;
    e[idx].next = head[a];
    e[idx].dis = c;

    head[a] = idx++;
}

void spfa()
{
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;

    queue<int> q;
    q.push(1);

    st[1] = true; //判重数组， 队列中有重复的点没有意义

    while (q.size())
    {
        int t = q.front();
        q.pop();

        st[t] = false;

        for (int i = head[t]; i != -1; i = e[i].next)
        {
            int j = e[i].to;
            if (dist[j] > dist[t] + e[i].dis)
            {
                dist[j] = dist[t] + e[i].dis;
                if (!st[j])
                {
                    q.push(j);
                    st[j] = true;
                }
            }
        }
    }
}

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    cin >> n >> m;

    memset(head, -1, sizeof head);

    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        add(a, b, c);
    }

    spfa();

    for (int i = 2; i <= n; i++)
    {
        cout << dist[i] << endl;
    }

    return 0;
}